/*   1:    */ package org.intellij.plugins.relaxNG.compact.lexer;
/*   2:    */ 
/*   3:    */

import org.kohsuke.rngom.parse.compact.CharStream;
import org.kohsuke.rngom.parse.compact.EOFException;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */ 
/*  10:    */ public class SimpleCharStream
/*  11:    */   implements CharStream
/*  12:    */ {
/*  13:    */   int bufsize;
/*  14:    */   int available;
/*  15:    */   int tokenBegin;
/*  16: 34 */   public int bufpos = -1;
/*  17:    */   protected int[] bufline;
/*  18:    */   protected int[] bufcolumn;
/*  19: 38 */   protected int column = 0;
/*  20: 39 */   protected int line = 1;
/*  21: 41 */   protected boolean prevCharIsCR = false;
/*  22: 42 */   protected boolean prevCharIsLF = false;
/*  23:    */   protected Reader inputStream;
/*  24:    */   protected char[] buffer;
/*  25: 47 */   protected int maxNextCharInd = 0;
/*  26: 48 */   protected int inBuf = 0;
/*  27:    */   
/*  28:    */   protected void ExpandBuff(boolean paramBoolean)
/*  29:    */   {
/*  30: 52 */     char[] arrayOfChar = new char[this.bufsize + 2048];
/*  31: 53 */     int[] arrayOfInt1 = new int[this.bufsize + 2048];
/*  32: 54 */     int[] arrayOfInt2 = new int[this.bufsize + 2048];
/*  33:    */     try
/*  34:    */     {
/*  35: 58 */       if (paramBoolean)
/*  36:    */       {
/*  37: 60 */         System.arraycopy(this.buffer, this.tokenBegin, arrayOfChar, 0, this.bufsize - this.tokenBegin);
/*  38: 61 */         System.arraycopy(this.buffer, 0, arrayOfChar, this.bufsize - this.tokenBegin, this.bufpos);
/*  39:    */         
/*  40: 63 */         this.buffer = arrayOfChar;
/*  41:    */         
/*  42: 65 */         System.arraycopy(this.bufline, this.tokenBegin, arrayOfInt1, 0, this.bufsize - this.tokenBegin);
/*  43: 66 */         System.arraycopy(this.bufline, 0, arrayOfInt1, this.bufsize - this.tokenBegin, this.bufpos);
/*  44: 67 */         this.bufline = arrayOfInt1;
/*  45:    */         
/*  46: 69 */         System.arraycopy(this.bufcolumn, this.tokenBegin, arrayOfInt2, 0, this.bufsize - this.tokenBegin);
/*  47: 70 */         System.arraycopy(this.bufcolumn, 0, arrayOfInt2, this.bufsize - this.tokenBegin, this.bufpos);
/*  48: 71 */         this.bufcolumn = arrayOfInt2;
/*  49:    */         
/*  50: 73 */         this.maxNextCharInd = (this.bufpos += this.bufsize - this.tokenBegin);
/*  51:    */       }
/*  52:    */       else
/*  53:    */       {
/*  54: 77 */         System.arraycopy(this.buffer, this.tokenBegin, arrayOfChar, 0, this.bufsize - this.tokenBegin);
/*  55: 78 */         this.buffer = arrayOfChar;
/*  56:    */         
/*  57: 80 */         System.arraycopy(this.bufline, this.tokenBegin, arrayOfInt1, 0, this.bufsize - this.tokenBegin);
/*  58: 81 */         this.bufline = arrayOfInt1;
/*  59:    */         
/*  60: 83 */         System.arraycopy(this.bufcolumn, this.tokenBegin, arrayOfInt2, 0, this.bufsize - this.tokenBegin);
/*  61: 84 */         this.bufcolumn = arrayOfInt2;
/*  62:    */         
/*  63: 86 */         this.maxNextCharInd = (this.bufpos -= this.tokenBegin);
/*  64:    */       }
/*  65:    */     }
/*  66:    */     catch (Throwable localThrowable)
/*  67:    */     {
/*  68: 91 */       throw new Error(localThrowable.getMessage());
/*  69:    */     }
/*  70: 95 */     this.bufsize += 2048;
/*  71: 96 */     this.available = this.bufsize;
/*  72: 97 */     this.tokenBegin = 0;
/*  73:    */   }
/*  74:    */   
/*  75:    */   protected void FillBuff()
/*  76:    */     throws EOFException
/*  77:    */   {
/*  78:102 */     if (this.maxNextCharInd == this.available) {
/*  79:104 */       if (this.available == this.bufsize)
/*  80:    */       {
/*  81:106 */         if (this.tokenBegin > 2048)
/*  82:    */         {
/*  83:108 */           this.bufpos = (this.maxNextCharInd = 0);
/*  84:109 */           this.available = this.tokenBegin;
/*  85:    */         }
/*  86:111 */         else if (this.tokenBegin < 0)
/*  87:    */         {
/*  88:112 */           this.bufpos = (this.maxNextCharInd = 0);
/*  89:    */         }
/*  90:    */         else
/*  91:    */         {
/*  92:114 */           ExpandBuff(false);
/*  93:    */         }
/*  94:    */       }
/*  95:116 */       else if (this.available > this.tokenBegin) {
/*  96:117 */         this.available = this.bufsize;
/*  97:118 */       } else if (this.tokenBegin - this.available < 2048) {
/*  98:119 */         ExpandBuff(true);
/*  99:    */       } else {
/* 100:121 */         this.available = this.tokenBegin;
/* 101:    */       }
/* 102:    */     }
/* 103:    */     try
/* 104:    */     {
/* 105:    */       int i;
/* 106:126 */       if ((i = this.inputStream.read(this.buffer, this.maxNextCharInd, this.available - this.maxNextCharInd)) == -1)
/* 107:    */       {
/* 108:129 */         this.inputStream.close();
/* 109:130 */         throw new IOException();
/* 110:    */       }
/* 111:133 */       this.maxNextCharInd += i;
/* 112:134 */       return;
/* 113:    */     }
/* 114:    */     catch (IOException localIOException)
/* 115:    */     {
/* 116:137 */       this.bufpos -= 1;
/* 117:138 */       backup(0);
/* 118:139 */       if (this.tokenBegin == -1) {
/* 119:140 */         this.tokenBegin = this.bufpos;
/* 120:    */       }
/* 121:141 */       throw new EOFException();
/* 122:    */     }
/* 123:    */   }
/* 124:    */   
/* 125:    */   public char BeginToken()
/* 126:    */     throws EOFException
/* 127:    */   {
/* 128:147 */     this.tokenBegin = -1;
/* 129:148 */     char c = readChar();
/* 130:149 */     this.tokenBegin = this.bufpos;
/* 131:    */     
/* 132:151 */     return c;
/* 133:    */   }
/* 134:    */   
/* 135:    */   protected void UpdateLineColumn(char paramChar)
/* 136:    */   {
/* 137:156 */     this.column += 1;
/* 138:158 */     if (this.prevCharIsLF)
/* 139:    */     {
/* 140:160 */       this.prevCharIsLF = false;
/* 141:161 */       this.line += (this.column = 1);
/* 142:    */     }
/* 143:163 */     else if (this.prevCharIsCR)
/* 144:    */     {
/* 145:165 */       this.prevCharIsCR = false;
/* 146:166 */       if (paramChar == '\n') {
/* 147:168 */         this.prevCharIsLF = true;
/* 148:    */       } else {
/* 149:171 */         this.line += (this.column = 1);
/* 150:    */       }
/* 151:    */     }
/* 152:174 */     switch (paramChar)
/* 153:    */     {
/* 154:    */     case '\r': 
/* 155:177 */       this.prevCharIsCR = true;
/* 156:178 */       break;
/* 157:    */     case '\n': 
/* 158:180 */       this.prevCharIsLF = true;
/* 159:181 */       break;
/* 160:    */     case '\t': 
/* 161:183 */       this.column -= 1;
/* 162:184 */       this.column += 8 - (this.column & 0x7);
/* 163:185 */       break;
/* 164:    */     }
/* 165:190 */     this.bufline[this.bufpos] = this.line;
/* 166:191 */     this.bufcolumn[this.bufpos] = this.column;
/* 167:    */   }
/* 168:    */   
/* 169:    */   public char readChar()
/* 170:    */     throws EOFException
/* 171:    */   {
/* 172:196 */     if (this.inBuf > 0)
/* 173:    */     {
/* 174:198 */       this.inBuf -= 1;
/* 175:200 */       if (++this.bufpos == this.bufsize) {
/* 176:201 */         this.bufpos = 0;
/* 177:    */       }
/* 178:203 */       return this.buffer[this.bufpos];
/* 179:    */     }
/* 180:206 */     if (++this.bufpos >= this.maxNextCharInd) {
/* 181:207 */       FillBuff();
/* 182:    */     }
/* 183:209 */     char c = this.buffer[this.bufpos];
/* 184:    */     
/* 185:211 */     UpdateLineColumn(c);
/* 186:212 */     return c;
/* 187:    */   }
/* 188:    */   
/* 189:    */   /**
/* 190:    */    * @deprecated
/* 191:    */    */
/* 192:    */   public int getColumn()
/* 193:    */   {
/* 194:221 */     return this.bufcolumn[this.bufpos];
/* 195:    */   }
/* 196:    */   
/* 197:    */   /**
/* 198:    */    * @deprecated
/* 199:    */    */
/* 200:    */   public int getLine()
/* 201:    */   {
/* 202:230 */     return this.bufline[this.bufpos];
/* 203:    */   }
/* 204:    */   
/* 205:    */   public int getEndColumn()
/* 206:    */   {
/* 207:234 */     return this.bufcolumn[this.bufpos];
/* 208:    */   }
/* 209:    */   
/* 210:    */   public int getEndLine()
/* 211:    */   {
/* 212:238 */     return this.bufline[this.bufpos];
/* 213:    */   }
/* 214:    */   
/* 215:    */   public int getBeginColumn()
/* 216:    */   {
/* 217:242 */     return this.bufcolumn[this.tokenBegin];
/* 218:    */   }
/* 219:    */   
/* 220:    */   public int getBeginLine()
/* 221:    */   {
/* 222:246 */     return this.bufline[this.tokenBegin];
/* 223:    */   }
/* 224:    */   
/* 225:    */   public void backup(int paramInt)
/* 226:    */   {
/* 227:251 */     this.inBuf += paramInt;
/* 228:252 */     if (this.bufpos -= paramInt < 0) {
/* 229:253 */       this.bufpos += this.bufsize;
/* 230:    */     }
/* 231:    */   }
/* 232:    */   
/* 233:    */   public SimpleCharStream(Reader paramReader, int paramInt1, int paramInt2, int paramInt3)
/* 234:    */   {
/* 235:259 */     this.inputStream = paramReader;
/* 236:260 */     this.line = paramInt1;
/* 237:261 */     this.column = (paramInt2 - 1);
/* 238:    */     
/* 239:263 */     this.available = (this.bufsize = paramInt3);
/* 240:264 */     this.buffer = new char[paramInt3];
/* 241:265 */     this.bufline = new int[paramInt3];
/* 242:266 */     this.bufcolumn = new int[paramInt3];
/* 243:    */   }
/* 244:    */   
/* 245:    */   public SimpleCharStream(Reader paramReader, int paramInt1, int paramInt2)
/* 246:    */   {
/* 247:272 */     this(paramReader, paramInt1, paramInt2, 4096);
/* 248:    */   }
/* 249:    */   
/* 250:    */   public SimpleCharStream(Reader paramReader)
/* 251:    */   {
/* 252:277 */     this(paramReader, 1, 1, 4096);
/* 253:    */   }
/* 254:    */   
/* 255:    */   public void ReInit(Reader paramReader, int paramInt1, int paramInt2, int paramInt3)
/* 256:    */   {
/* 257:282 */     this.inputStream = paramReader;
/* 258:283 */     this.line = paramInt1;
/* 259:284 */     this.column = (paramInt2 - 1);
/* 260:286 */     if ((this.buffer == null) || (paramInt3 != this.buffer.length))
/* 261:    */     {
/* 262:288 */       this.available = (this.bufsize = paramInt3);
/* 263:289 */       this.buffer = new char[paramInt3];
/* 264:290 */       this.bufline = new int[paramInt3];
/* 265:291 */       this.bufcolumn = new int[paramInt3];
/* 266:    */     }
/* 267:293 */     this.prevCharIsLF = (this.prevCharIsCR = 0);
/* 268:294 */     this.tokenBegin = (this.inBuf = this.maxNextCharInd = 0);
/* 269:295 */     this.bufpos = -1;
/* 270:    */   }
/* 271:    */   
/* 272:    */   public void ReInit(Reader paramReader, int paramInt1, int paramInt2)
/* 273:    */   {
/* 274:301 */     ReInit(paramReader, paramInt1, paramInt2, 4096);
/* 275:    */   }
/* 276:    */   
/* 277:    */   public void ReInit(Reader paramReader)
/* 278:    */   {
/* 279:306 */     ReInit(paramReader, 1, 1, 4096);
/* 280:    */   }
/* 281:    */   
/* 282:    */   public SimpleCharStream(InputStream paramInputStream, int paramInt1, int paramInt2, int paramInt3)
/* 283:    */   {
/* 284:311 */     this(new InputStreamReader(paramInputStream), paramInt1, paramInt2, 4096);
/* 285:    */   }
/* 286:    */   
/* 287:    */   public SimpleCharStream(InputStream paramInputStream, int paramInt1, int paramInt2)
/* 288:    */   {
/* 289:317 */     this(paramInputStream, paramInt1, paramInt2, 4096);
/* 290:    */   }
/* 291:    */   
/* 292:    */   public SimpleCharStream(InputStream paramInputStream)
/* 293:    */   {
/* 294:322 */     this(paramInputStream, 1, 1, 4096);
/* 295:    */   }
/* 296:    */   
/* 297:    */   public void ReInit(InputStream paramInputStream, int paramInt1, int paramInt2, int paramInt3)
/* 298:    */   {
/* 299:328 */     ReInit(new InputStreamReader(paramInputStream), paramInt1, paramInt2, 4096);
/* 300:    */   }
/* 301:    */   
/* 302:    */   public void ReInit(InputStream paramInputStream)
/* 303:    */   {
/* 304:333 */     ReInit(paramInputStream, 1, 1, 4096);
/* 305:    */   }
/* 306:    */   
/* 307:    */   public void ReInit(InputStream paramInputStream, int paramInt1, int paramInt2)
/* 308:    */   {
/* 309:338 */     ReInit(paramInputStream, paramInt1, paramInt2, 4096);
/* 310:    */   }
/* 311:    */   
/* 312:    */   public String GetImage()
/* 313:    */   {
/* 314:342 */     if (this.bufpos >= this.tokenBegin) {
/* 315:343 */       return new String(this.buffer, this.tokenBegin, this.bufpos - this.tokenBegin + 1);
/* 316:    */     }
/* 317:345 */     return new String(this.buffer, this.tokenBegin, this.bufsize - this.tokenBegin) + new String(this.buffer, 0, this.bufpos + 1);
/* 318:    */   }
/* 319:    */   
/* 320:    */   public char[] GetSuffix(int paramInt)
/* 321:    */   {
/* 322:351 */     char[] arrayOfChar = new char[paramInt];
/* 323:353 */     if (this.bufpos + 1 >= paramInt)
/* 324:    */     {
/* 325:354 */       System.arraycopy(this.buffer, this.bufpos - paramInt + 1, arrayOfChar, 0, paramInt);
/* 326:    */     }
/* 327:    */     else
/* 328:    */     {
/* 329:357 */       System.arraycopy(this.buffer, this.bufsize - (paramInt - this.bufpos - 1), arrayOfChar, 0, paramInt - this.bufpos - 1);
/* 330:    */       
/* 331:359 */       System.arraycopy(this.buffer, 0, arrayOfChar, paramInt - this.bufpos - 1, this.bufpos + 1);
/* 332:    */     }
/* 333:362 */     return arrayOfChar;
/* 334:    */   }
/* 335:    */   
/* 336:    */   public void Done()
/* 337:    */   {
/* 338:367 */     this.buffer = null;
/* 339:368 */     this.bufline = null;
/* 340:369 */     this.bufcolumn = null;
/* 341:    */   }
/* 342:    */   
/* 343:    */   public void adjustBeginLineColumn(int paramInt1, int paramInt2)
/* 344:    */   {
/* 345:377 */     int i = this.tokenBegin;
/* 346:    */     int j;
/* 347:380 */     if (this.bufpos >= this.tokenBegin) {
/* 348:382 */       j = this.bufpos - this.tokenBegin + this.inBuf + 1;
/* 349:    */     } else {
/* 350:386 */       j = this.bufsize - this.tokenBegin + this.bufpos + 1 + this.inBuf;
/* 351:    */     }
/* 352:389 */     int k = 0;int m = 0;int n = 0;
/* 353:390 */     int i1 = 0;int i2 = 0;
/* 354:392 */     while ((k < j) && (this.bufline[(m = i % this.bufsize)] == this.bufline[(n = ++i % this.bufsize)]))
/* 355:    */     {
/* 356:395 */       this.bufline[m] = paramInt1;
/* 357:396 */       i1 = i2 + this.bufcolumn[n] - this.bufcolumn[m];
/* 358:397 */       this.bufcolumn[m] = (paramInt2 + i2);
/* 359:398 */       i2 = i1;
/* 360:399 */       k++;
/* 361:    */     }
/* 362:402 */     if (k < j)
/* 363:    */     {
/* 364:404 */       this.bufline[m] = (paramInt1++);
/* 365:405 */       this.bufcolumn[m] = (paramInt2 + i2);
/* 366:407 */       while (k++ < j) {
/* 367:409 */         if (this.bufline[(m = i % this.bufsize)] != this.bufline[(++i % this.bufsize)]) {
/* 368:410 */           this.bufline[m] = (paramInt1++);
/* 369:    */         } else {
/* 370:412 */           this.bufline[m] = paramInt1;
/* 371:    */         }
/* 372:    */       }
/* 373:    */     }
/* 374:416 */     this.line = this.bufline[m];
/* 375:417 */     this.column = this.bufcolumn[m];
/* 376:    */   }
/* 377:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.lexer.SimpleCharStream

 * JD-Core Version:    0.7.0.1

 */